package br.rui.servlets;

import javax.servlet.http.HttpServlet;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import br.rui.persistencia.ContaDB;

/**
 * Servlet Class
 *
 * @web.servlet              name="Relatorio"
 *                           display-name="Name for Relatorio"
 *                           description="Description for Relatorio"
 * @web.servlet-mapping      url-pattern="/Relatorio"
 * @web.servlet-init-param   name="A parameter"
 *                           value="A value"
 */
@SuppressWarnings("serial")
public class Relatorio extends HttpServlet {

	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
		throws ServletException, IOException {
		
		ContaDB contadb = new ContaDB();
		RequestDispatcher rd;
		ArrayList lista = new ArrayList();
		String jspDestino = null;
		int key = Integer.parseInt(req.getParameter("key"));
		switch (key) {
		case 1:
			lista = (ArrayList) contadb.Associados();
			req.setAttribute("associados",lista);
			jspDestino = "/web/jsp/ImprAssociados.jsp";
			break;
			
		case 2:
			lista = (ArrayList) contadb.ConsultarPCRui(null);
			req.setAttribute("pendentesRui",lista);
			jspDestino = "/web/jsp/ImprRuiPend.jsp";
			break;

		case 3:
			lista = (ArrayList) contadb.ConsultarOutros(null);
			req.setAttribute("pendentesOutros",lista);
			jspDestino = "/web/jsp/ImprLigaPend.jsp";
			break;
			
		case 4:
			lista = (ArrayList) contadb.ConsultarClientes();
			req.setAttribute("clientes",lista);
			jspDestino = "/web/jsp/ImprClientes.jsp";
		default:
			break;
		}
		rd = getServletContext().getRequestDispatcher(jspDestino);
		rd.forward(req,resp);
	}

	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
		throws ServletException,
		IOException {
		doGet(req, resp);
	}

}
